package daily.play1;

import java.util.*;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

//public class demo10 {
//    public static void main(String[] arga){
//        ArrayList<Integer> list = new ArrayList<>();
//        list.add(1);
//        list.add(2);
//        list.add(3);
//        list.add(4);
//        Collections.sort(list);
//        System.out.println(list);
//        Collections.swap(list,0,list.size()-1);
//        System.out.println(list);
//        Collections.shuffle(list);
//        System.out.println(list);
//        Collections.addAll(list,1,2,3,4,5,6);
//        Random ran = new Random();
//        int index = ran.nextInt(list.size());
//        System.out.println(list.get(index));

//        Collections.shuffle(list);
//        System.out.println(list.get(0));
//    }
//}


//public class demo10{
//    public static void main(String[] args){
//        ArrayList<Integer> list = new ArrayList();
//        Collections.addAll(list,1,1,1,1,1,1,0,0,0);
//        Collections.shuffle(list);
//        Random  ran = new Random();
//        int cla = ran.nextInt(list.size());
//        System.out.println(list.get(cla));
//        ArrayList<String> boylist = new ArrayList<>();
//        ArrayList<String> girllist = new ArrayList<>();
//        Collections.addAll(boylist,"张三","李四","王五");
//        Collections.addAll(girllist,"小梅","小美");
//
//        if(list.get(cla)==1){
//            int index = ran.nextInt(boylist.size());
//            System.out.println(boylist.get(index));
//        }
//        else{
//            int index = ran.nextInt(girllist.size());
//            System.out.println(girllist.get(index));
//        }
//    }
//}

//不重复点名
//public class demo10{
//    public static void main(String[] args){
//        ArrayList<String> list1 = new ArrayList<>();
//        Collections.addAll(list1,"张三","李四","王五","小梅","小美");
//        int temp = list1.size();
//        ArrayList<String> list2 = new ArrayList<>();
//        Random ran = new Random();
//        for (int i = 0; i < 10; i++) {
//            System.out.printf("==========第%d轮点名========\n",i+1);
//            Collections.shuffle(list1);
//            for(int j=0;j<temp;j++){
//                String name = list1.remove(0);
//                System.out.println(name);
//                list2.add(name);
//            }
//            list1.addAll(list2);
//            list2.clear();
//        }
//    }
//}
//public class demo10 {
//    public static void main(String[] args) {
//        System.out.printf("==========第%d轮点名========\r",1);
//        System.out.println(1);
//        System.out.printf("==========第%d轮点名========\n",1);
//    }
//}


//public class demo10 {
//    public static void main(String[] args) {
//        HashMap<String, ArrayList<String>> map = new HashMap<>();
//        ArrayList<String> list1 = new ArrayList<>();
//        ArrayList<String> list2 = new ArrayList<>();
//        ArrayList<String> list3 = new ArrayList<>();
//        Collections.addAll(list1, "信阳", "洛阳", "郑州", "南阳");
//        Collections.addAll(list2, "广州", "深圳", "佛山", "珠海");
//        Collections.addAll(list3, "武汉", "黄冈", "孝感", "咸宁");
//        map.put("河南", list1);
//        map.put("广东", list1);
//        map.put("湖北", list1);
////        System.out.println(map);
//        Set<Map.Entry<String, ArrayList<String>>> set = map.entrySet();
//        Iterator<Map.Entry<String, ArrayList<String>>> it = set.iterator();
//        while (it.hasNext()) {
//            Map.Entry<String, ArrayList<String>> entry = it.next();
//            System.out.print(entry.getKey() + "=");
//            ArrayList<String> array = entry.getValue();
//            for (int i = 0; i < array.size(); i++) {
//                if (i != array.size() - 1) {
//                    System.out.print(array.get(i) + ",");
//                } else {
//                    System.out.println(array.get(i));
//                }
//            }
//        }
//    }
//}

//stream的使用
//public  class demo10{
//    public static void main(String[] args) {
//        int []arr =new int [10];
//        Arrays.fill(arr,1);
//        Arrays.stream(arr).forEach(s-> System.out.println(s));
//    }
//}

//一推零散的数据
/*
public  class demo10{
    public static void main(String[] args) {
        Stream.of(1,2,3,4,5,6,7,8,9).forEach(s-> System.out.println(s));
    }
}*/

//public class demo10 {
//    public static void main(String[] args) {
//        StringJoiner sj = new StringJoiner(",",".",".");
//        sj.add("a");
//        sj.add("b");
//        sj.add("c");
//        sj.add("d");
//        System.out.println(sj.toString());
//        ArrayList<String> list = new ArrayList<>();
//        ArrayList<String> list1 = new ArrayList<>();
//        Collections.addAll(list, "张强-1", "李四-2", "王-3", "王阿三-4", "张无忌-5");
//
//        List<String> col = list.stream().collect(Collectors.toList());
//        System.out.println(col);
//
//        Set<String> coll = list.stream().collect(Collectors.toSet());
//        System.out.println(coll);
//
//        Map<String, Integer> colll = list.stream().collect(Collectors.toMap(new Function<String, String>() {
//            @Override
//            public String apply(String s) {
//                return s.split("-")[0];
//            }
//        }, new Function<String, Integer>() {
//            @Override
//            public Integer apply(String s) {
//                return Integer.parseInt(s.split("-")[1]);
//            }
//        }));
//        System.out.println(colll);
//        list.stream().collect(Collectors.toMap(s->s.split("-")[0],s-> Integer.parseInt(s.split("-")[1])));
//        Collections.addAll(list1, "赵六");
//        //参数的作用是：创建一个指定类型和大小的数组
//        //toarray底层回将流中的数据放到数组中
//        //同时会返回一个带有数据的数组
//        String[] arr = list.stream().toArray(new IntFunction<String[]>() {
//            @Override
//            public String[] apply(int value) {
//                return new String[value];
//            }
//        });
//
//        //方式二lambda表达式
//        String [] arr1 = list.stream().toArray(value -> new String[value]);
//        System.out.println(Arrays.toString(arr1));
//        System.out.println(Arrays.toString(arr));
//        list.stream().forEach(s-> System.out.println(s));
//        list.stream().filter(s -> s.length()==2).forEach(s-> System.out.println(s));
//        list.stream().limit(3).forEach(s-> System.out.println(s));
//        list.stream().skip(3).forEach(s-> System.out.println(s));
//
//        Stream.concat(list.stream(),list1.stream()).forEach(s-> System.out.println(s));
//        list.stream().map(new Function<String, Object>() {
//            @Override
//            public Object apply(String s) {
//                String[] sp = s.split("-");
//                int age = Integer.parseInt(sp[1]);
//                return age;
//            }
//        }).forEach(s-> System.out.println(s));


        //方式二
//        list.stream().map(s->Integer.parseInt(s.split("-")[1])).forEach(s-> System.out.println(s));
//    }
//}

//class Actor{
//    public String name;
//    public int age;
//    public Actor(String name, int age) {
//        this.name = name;
//        this.age = age;
//    }
//    public String toString(){
//        return "name:"+name+",age:"+age;
//    }
//}
//
//public class demo10{
//    public static void main(String[] args){
//        List<Integer> col = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).filter(s -> (s % 2 == 0)).collect(Collectors.toList());
//        System.out.println(col);
//        System.out.println(Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).filter(s -> s % 2 == 1).collect(Collectors.toList()));
//    ArrayList<String> list = new ArrayList<>();
//    Collections.addAll(list,"zhangsan,23","lisi,24","wangwu,25");
//        Map<String, String> col = list.stream().filter(s -> "24".compareTo(s.split(",")[1]) <= 0).collect(Collectors.toMap(s -> s.split(",")[0], s -> s.split(",")[1]));
//        System.out.println(col);


//        ArrayList<String> manList = new ArrayList<>();
//        ArrayList<String> womanList = new ArrayList<>();
//        Collections.addAll(manList,"张三,12","李四,15","王五,25","赵六,19","力气,36","例子,24","六六,12");
//        Collections.addAll(womanList,"李智恩,12","金智媛,15","林允儿,25","杨艺珍,19","杨诗诗,36","例子,24","六六,12");

//        List<String> col = manList.stream().filter(s -> s.split(",")[0].length() == 3).limit(2).collect(Collectors.toList());
//        col.addAll(womanList.stream().filter(s->s.startsWith("杨")).skip(1).collect(Collectors.toList()));
//        Iterator <String> it = col.iterator();
//        List<Actor> list = new ArrayList<>();
//        while(it.hasNext()){
//            String str = it.next();
//            list.add(new Actor(str.split(",")[0],Integer.parseInt(str.split(",")[1]))) ;
//        }
//        System.out.println(list);



//        Stream<String> stream1 = manList.stream().filter(s -> s.split(",")[0].length() == 3).limit(2);
//        Stream<String> stream2 = womanList.stream().filter(s -> s.startsWith("杨")).skip(1);
//        List<Actor> list = Stream.concat(stream1, stream2).map(s->new Actor(s.split(",")[0],Integer.parseInt(s.split(",")[1]))
//            @Override
//            public Actor apply(String s) {
//                String name = s.split(",")[0];
//                int age = Integer.parseInt(s.split(",")[1]);
//
//                return new Actor(name, age);
//            }
//        ).collect(Collectors.toList());
//        System.out.println(list);
//    }
//}


